home *** CD-ROM | disk | FTP | other *** search
- Path: isonews.bbn.hp.com!hpbblb!news
- From: Matthias Dittrich <matti>
- Newsgroups: comp.lang.c
- Subject: Re: Simple Program Question
- Date: 28 Feb 1996 07:32:29 GMT
- Organization: Hewlett-Packard Co.
- Message-ID: <4h10ed$5es@hpbblb.bbn.hp.com>
- References: <4gsr9u$sk6@newsbf02.news.aol.com>
- NNTP-Posting-Host: trabant.bbn.hp.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1N (X11; I; HP-UX A.09.07 9000/712)
- X-URL: news:4gsr9u$sk6@newsbf02.news.aol.com
-
- tycope@aol.com (Tycope) wrote:
- >I am trying to write a non -interactive program that calculates all
- >integer triples (i, j, k) such that
- >0 < i < j < k < l and i + j + k = l. Print out the number of triples that
- >satisfy the requirements and print out every millionth triple. Can anyone
- >see where I am missing the boat in the following code. The program runs
- >and immediately terminates. Thanks in advance for any feedback.
- >
- >#include <stdio.h>
- >
- >long int i, j, k, l;
- >long int count;
- >
- >int
- >main (void)
- >{
- > do
- > {
- > (l = i + j + k);
- > (i = 1);
- > (j = 2);
- > (k = 3);
- If you are initializing i, j and k every time in the loop, you will get the
- same result in each line.
-
- > (i++, j++, k++);
- > (++count);
- > if (count % 1000000 == 0)
- > {
- > printf("%ld(i) + %ld(j) + %ld(k) = %ld(l)", i, j, k, l);
- A '\n' in the format would be nice: ^^
- printf("%ld(i) + %ld(j) + %ld(k) = %ld(l)\n", ...
- > }
- >
- > } while (0 < i < j < k < l);
- You have to split this statement:
- while(0<i && i<j && j<k && k<l);
- Otherwise the following will be done:
- Assuming k<l, then it results 1 and next you will compare j<1 which is false
- and your loop finishs.
- >
- > return (0);
- >}
- I can't see where you are checking your condition (i+j+k) == l and how
- to evaluate l. At present the value of l is zero because i, j and k are
- global and therefore initialized to zero.
-
- Hope this will help you,
- Matthias
-
-